package com.example.zbh.dsliao.ui;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.example.zbh.dsliao.ui.fragment.MyMusicFragment;
import com.example.zbh.dsliao.ui.fragment.RecommendFragment;
import com.example.zbh.dsliao.ui.fragment.SearchFragment;

/**
 * Created by yaolin on 15/11/19.
 */
public class FragmentFactory {




    private static SparseArray<Fragment> fragmentMap = new SparseArray<>();


    public static Fragment createFragment(int position){
        Fragment f = fragmentMap.get(position);
        if(f == null){
            switch (position){
                case 0:
                    f = new RecommendFragment();
                    break;
                case 1:
                    f = new MyMusicFragment();
                    break;
                case 2:
                    f = new SearchFragment();
            }
            fragmentMap.put(position, f);
        }
        return f;
    }
}
